/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.alibaba.fastjson.JSONValidator;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.entity.KjProjectContribute;
import com.jeesite.modules.kj.service.KjProjectContributeService;

/**
 * kj_project_contributeController
 * @author hzy
 * @version 2021-07-13
 */
@Controller
@RequestMapping(value = "${adminPath}/kj/kjProjectContribute")
public class KjProjectContributeController extends BaseController {

	@Autowired
	private KjProjectContributeService kjProjectContributeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public KjProjectContribute get(String id, boolean isNewRecord) {
		return kjProjectContributeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjProjectContribute:view")
	@RequestMapping(value = {"list", ""})
	public String list(KjProjectContribute kjProjectContribute, Model model) {
		model.addAttribute("kjProjectContribute", kjProjectContribute);
		return "modules/kj/kjProjectContributeList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjProjectContribute:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<KjProjectContribute> listData(KjProjectContribute kjProjectContribute, HttpServletRequest request, HttpServletResponse response) {
		kjProjectContribute.setPage(new Page<>(request, response));
		Page<KjProjectContribute> page = kjProjectContributeService.findPage(kjProjectContribute);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("kj:kjProjectContribute:view")
	@RequestMapping(value = "form")
	public String form(KjProjectContribute kjProjectContribute, Model model) {
		model.addAttribute("kjProjectContribute", kjProjectContribute);
		return "modules/kj/kjProjectContributeForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("kj:kjProjectContribute:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated KjProjectContribute kjProjectContribute) {
		kjProjectContributeService.save(kjProjectContribute);
		return renderResult(Global.TRUE, text("保存捐赠表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("kj:kjProjectContribute:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(KjProjectContribute kjProjectContribute) {
		kjProjectContributeService.delete(kjProjectContribute);
		return renderResult(Global.TRUE, text("删除捐赠表成功！"));
	}
	
	/**
	 * 列表选择对话框
	 */
	@RequiresPermissions("kj:kjProjectContribute:view")
	@RequestMapping(value = "kjProjectContributeSelect")
	public String empUserSelect(KjProjectContribute kjProjectContribute, String selectData, Model model) {
		String selectDataJson = EncodeUtils.decodeUrl(selectData);
		if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
			model.addAttribute("selectData", selectDataJson);
		}
		model.addAttribute("KjProjectContribute", kjProjectContribute);
		return "modules/kj/kjProjectContributeSelect";
	}
	
}